import { useConfig } from '../stores/config'
import createAxios from '../utils/axios'
import { useUserInfo } from '../stores/userInfo'

// 获取配置信息





// 获取推荐栏目
export const getPropose = (): any => {
  const config = useConfig()
  const propose = config.getPropose();
  if(propose){
    return propose;
  }


  getConfig()

  return config.getPropose();
}


// 请求 获取配置信息
export const getConfig = async (): void =>{
    // 初始化
    const config = useConfig()
    const usernfo = useUserInfo()
    // 执行请求
    await createAxios({
        url: '/frontend/home/init',
        method: 'post',
      })
        .then((res) => {
          //const config = useConfig()
          config.setPropose(res.data.propose)
          config.setTree(res.data.tree)
          config.setSite(res.data.config)

          usernfo.dataFill(res.data.user)

        })
        .catch((err) => {
          console.log('初始化请求失败', err)

          return false
        })
}

